<template>
    <div>
        <el-form :rules="rules" ref="formLogin" :model="form"  class="loginContainer">
            <h3 class="loginTitle">系统登录</h3>
            <el-form-item prop="name">
                <el-input prefix-icon="el-icon-user" type="text" placeholder="请输入用户名" v-model="form.name" ></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input prefix-icon="el-icon-postcard" type="password" placeholder="请输入密码" v-model="form.password"></el-input>
            </el-form-item>
            <el-checkbox v-model="check" class="loginRemember">记住我</el-checkbox>
            <el-button type="primary" style="width: 100%" @click="_loginSubmit('formLogin')">登录</el-button>
        </el-form>
    </div>
</template>

<script>
    import {postReq} from "../utils/api";

    export default {
        name: "Login",
        data(){
            return {
                form:{
                    name:'',
                    password:'',
                    code:''
                },
                check:true,
                rules:{
                    name: [
                        { required: true, message: '请填写用户名', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请填写用户名密码', trigger: 'blur' }
                    ]
                }
            }
        },
        methods:{
            _loginSubmit(formName){
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        postReq('/api/sys_user/captcha')

                        // this.$router.push('/home')
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },

            _updateCaptcha(){
                this.captchaUrl = '/v1/sys_user/captcha'

            }
        }
    }
</script>

<style>
    .loginContainer{
        border-radius: 15px;
        background-clip: padding-box;
        margin: 180px auto;
        width: 350px;
        padding: 15px 35px 15px 35px;
        background: #fff;
        border: 1px solid #eaeaea;
        box-shadow: 0 0 25px #cac6c6;
    }

    .loginTitle{
        margin: 8px auto 40px auto;
        text-align: center;
    }
    .loginRemember{
        text-align: left;
        margin: 0px 0px 15px 0px;
    }

</style>